package yawning.mew.cat;

import yawning.mew.BuffsDebuffs.Buff;
import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EventHeroism extends SimulationEventAction {
	CatModelSimState mState;
	double mCooldownExpireTime;

	EventHeroism(CatModelSimState state) {
		super(state.mSimEngine);
		mState = state;

		if (!mState.mModel.buffsDebuffs.isBuff(Buff.MAJORHASTE)) mCooldownExpireTime = Double.MAX_VALUE;
	}

	@Override
	public double perform() {
		if (mCooldownExpireTime <= mState.mSimEngine.getSimTime() && mState.mModel.buffsDebuffs.isBuff(Buff.MAJORHASTE)) {
			// Heroism now!  Pew Pew Pew.
			schedule(mState.mModel.heroismBuffDuration);
			mState.mModel.multiplyHaste(mState.mModel.buffHeroism);
			mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.heroismCDDuration;

			if (mState.mIsLogging) mState.mLog.log("Heroism\n");

			return 0.0;
		}
		return SimulationAction.ACTION_FAIL;
	}

	@Override
	public void onExpire() {
		mState.mModel.multiplyHaste(1.0 / mState.mModel.buffHeroism);

		if (mState.mIsLogging) mState.mLog.log("Heroism: Expiration\n");
	}
}